package com.tongshu.naive.chat.socket;

import codec.ObjDecoder;
import codec.ObjEncoder;
import com.tongshu.naive.chat.application.UserService;
import com.tongshu.naive.chat.socket.handler.*;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
    private UserService userService;

    public MyChannelInitializer(UserService userService) {
        this.userService = userService;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        // 对象传输处理 解码
        socketChannel.pipeline().addLast(new ObjDecoder());
        // 在管道中添加我们自己的接收数据实现方法
        socketChannel.pipeline().addLast(new AddFriendHandler(userService));
        socketChannel.pipeline().addLast(new DelTalkHandler(userService));
        socketChannel.pipeline().addLast(new LoginHandler(userService));
        socketChannel.pipeline().addLast(new MsgGroupHandler(userService));
        socketChannel.pipeline().addLast(new MsgHandler(userService));
        socketChannel.pipeline().addLast(new ReconnectHandler(userService));
        socketChannel.pipeline().addLast(new SearchFriendHandler(userService));
        socketChannel.pipeline().addLast(new TalkNoticeHandler(userService));
        // 对象传输处理 编码
        socketChannel.pipeline().addLast(new ObjEncoder());
    }
}
